Prepare Interview

Mock Exams

Make Homepage

Bookmark this page

Subscribe Email Address

Java 11 Interview Questions and Answers

Question: What is Local-Variable Syntax for Lambda Parameters in Java 11?
Answer:

It allows var to be used when declaring the formal parameters of implicitly typed lambda expressions.

In Java 10, Local Variable Type Inference was introduced.

var str = "Java 10"; // infers Stringvar list = new ArrayList<String>(); // infers ArrayList<String>var stream = list.stream(); // infers Stream<String>svar bos = new ByteArrayOutputStream();

Java 11, allows var to be used to declare the formal parameters of an implicitly typed lambda expression.

(var a, var b) -> a + b

The examples below are illegal:

// Not allowed to mix 'var' and 'no var' in implicitly typed lambda expression(var a, b) -> a+b// Not allowed to mix 'var' and manifest types in explicitly typed lambda expression(var a, int b) -> a+b   
Is it helpful? Yes No

Most helpful rated by users:

©2024 WithoutBook